#include "widget.h"
#include "ui_widget.h"
#include<QPainter>
#include<QFont>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}
 void Widget::paintEvent(QPaintEvent *event)
 {
     (void)event;
     QPainter painter(this);   //栈上的变量，不需要考虑释放的问题
     QFont font("微软雅黑",24);

     QPen pen;
     pen.setColor(QColor(255,0,0));
     pen.setStyle(Qt::DashLine);//虚线
     pen.setWidth(5);
     painter.setPen(pen);


     QBrush brush;
     brush.setColor(QColor(0,255 ,0));
     brush.setStyle(Qt::Dense2Pattern);
     painter.setBrush(brush);


     painter.setFont(font);
     //画一个线段
     painter.drawLine(20,20,200,200);  //起点坐标到终点坐标
     //画一个矩形
     painter.drawRect(100,100,300,300);   //左上角坐标，宽高
     //画一个圆
     painter.drawEllipse(200,200,100,100);  //圆心，宽，高
     //写文字
     painter.drawText(0,100,"hello");     //坐标（0表示文字的最左侧，100表示基线）以及内容
 }

